home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / stdio / sscanf.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  747b  |  52 lines

  1.  
  2. /*
  3.  *  SSCANF.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  */
  9.  
  10. #include <stdarg.h>
  11. #include <stdio.h>
  12. #include <lib/misc.h>
  13.  
  14. static int
  15. _sgetc(sst)
  16. unsigned char **sst;
  17. {
  18.     unsigned char *ptr = *sst;
  19.     if (*ptr) {
  20.     *sst = ptr + 1;
  21.     return(*ptr);
  22.     }
  23.     return(EOF);
  24. }
  25.  
  26. static int
  27. _sungetc(c, sst)
  28. int c;
  29. unsigned char **sst;
  30. {
  31.     --*sst;
  32. }
  33.  
  34. int
  35. sscanf(buf, ctl, ...)
  36. char *buf;
  37. const char *ctl;
  38. {
  39.     char *ptr = buf;
  40.     int error;
  41.     int cnt;
  42.     va_list va;
  43.  
  44.     va_start(va, ctl);
  45.     error = _sfmt(ctl, va, _sgetc, _sungetc, &ptr, &cnt);
  46.     va_end(va);
  47.     if (error)
  48.     return(error);
  49.     return(cnt);
  50. }
  51.  
  52.